<template>
  <div>
    <div class="tableHeader">
      <div class="tableHeaderTitle">新闻列表</div>
      <div class="tableHeaderMenu">
        <el-button-group>
          <el-button icon="el-icon-refresh" @click="refreshData" size="mini"></el-button>
        </el-button-group>
      </div>
    </div>
    <el-table ref="multipleTable" :data="newsInfoData" tooltip-effect="dark" style="width: 100%">
      <el-table-column prop="ni_id" label="新闻ID" width="80"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="ni_title" label="新闻标题"></el-table-column>
      <el-table-column prop="u_nickname" label="发布人"></el-table-column>
      <el-table-column prop="ni_status" label="状态">
          <template slot-scope="scope">
            <b v-if="scope.row.ni_status == 0" style="color:gery">未审核</b>
            <b v-if="scope.row.ni_status == 1" style="color:green">已通过</b>
            <b v-if="scope.row.ni_status == 2" style="color:red">未通过</b>
        </template>
      </el-table-column>
      <el-table-column prop="nc_name" label="所属类别"></el-table-column>
      <el-table-column label="操作" fixed="right" width="260">
        <template slot-scope="scope">  
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button v-if="scope.row.ni_status == 1" size="mini" @click="handleAudit(scope.$index, scope.row, 2)">驳回</el-button>
          <el-button v-if="scope.row.ni_status == 0 || scope.row.ni_status == 2" size="mini" @click="handleAudit(scope.$index, scope.row, 1)">通过</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-sizes="[20,50,100,200]"
        :page-size="pagination.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagination.dataLength"
      ></el-pagination>
    </el-col>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  //数据源
  data() {
    return {};
  },
  //初始化函数
  mounted() {
    //获取新闻列表
    this.initData();
  },
  //计算属性
  computed: {
    ...mapState({
      newsInfoData : state => state.newsInfoListModule.newsInfoData,
      pagination   : state => state.newsInfoListModule.pagination
    })
  },
  //组件方法
  methods: {
    ...mapMutations(["newsInfoListModule/updateNewsInfoData"]),

    initData() {
      //获取分类列表
      this.$myLoading.startLoading();
      this.$http.getHttp(
        this.$API.newsSearchDetail +
          "/skip/" +
          this.pagination.skip +
          "/limit/" +
          this.pagination.pageSize +
          "/count/1/ni_is_delete/0/sort_order/ni_id-desc",
        rs => {
     
          this.$myLoading.endLoading();
          this["newsInfoListModule/updateNewsInfoData"](rs.data);
          this.pagination.dataLength = parseInt(rs.count);
        }
      );
    },

    refreshData() {
        this.initData();
    },

    handleEdit(index,item){
        this.$router.push({
            path: "/editNewsInfo",
            query : {
                ni_id : item.ni_id
            }
        });
    },

    handleDelete(index,item){

        var params = {
            delete_where : "ni_id",
            ni_id        : item.ni_id,
            ni_is_delete : 1
        };

        this.$myPop.confirmBox("确认操作","确定要删除该新闻吗？",()=>{

            this.$myLoading.startLoading();
            this.$http.postHttp(
                this.$API.newsDelete,
                params,
                rs => {
                    this.$myLoading.endLoading()
                    this.$myPop.SuccessMessage()
                    this.initData()
                }
            );

        });

    },

    handleAudit(index,item, audit){

        var params = {
            update_where : "ni_id",
            ni_id        : item.ni_id,
            ni_status    : audit
        };

        this.$myPop.confirmBox("确认操作","确定要对该新闻进行审核操作吗？",()=>{

            this.$myLoading.startLoading();
            this.$http.postHttp(
                this.$API.newsUpdate,
                params,
                rs => {

                    console.log(22222)
                 
                    this.$myLoading.endLoading()
                    this.$myPop.SuccessMessage()
                    setTimeout(()=>{
                      this.initData()
                    },1500)
                    
                }
            );

        });
    },

    handleSizeChange(){


    },

    handleCurrentChange(){

    }
  }
};
</script>

<style lang="stylus" scoped>
</style>